<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue基础</title>
</head>

<body>
  <div id="app">
    <!-- 双向数据绑定 !!!  只对表单元素有用 -->
    <input v-model="username" id="username" type="text">{{username}}

    <p>
      <input type="radio" v-model="gender" value="male" /> 男
      <input type="radio" v-model="gender" value="female" /> 女
    </p>
    
    <p>
      <input type="checkbox" v-model="eat" value="猪肉" />
      <input type="checkbox" v-model="eat" value="牛肉" />
      <input type="checkbox" v-model="eat" value="羊肉" />
    </p>
    <button @click="usernameHandler"></button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.8/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        username: '',
        gender: 'male',
        eat: []
      },
      methods: {
        usernameHandler() {
          console.log(this.username);
        }
      }
    });

    // const username = document.getElementById('username');
    // username.oninput = function () {
    //   console.log(this.value);
    // }
  </script>
</body>

</html>